/**
 * @author:fangxiaohua
*  @邮箱：abc2710712@qq.com
*  @qq:1295168875
*   用户业务操作操作
*/
void(function(exports){
	//数据库操作
	var dbLib = require('../lib/dbLib');
	//工具类模块
	var tools = require('../lib/toolsLib');
	
	//用户列表
	exports.list = function(req, res){
		var pageNo=req.body.pageNo;
		var pageSize=req.body.pageSize;
		var q=req.body.q;
		var status=req.body.status;
		var  sql=[" select v.*,u1.account as raccount,u2.account as braccount ",
				  		" from t_report_verify v ",
						" inner join t_user u1 on v.report_user=u1.id ",
						" inner join t_user u2 on v.be_report_user=u2.id ", 
						" where 1=1 and (v.reason  like ? or u1.account like ? or u2.account like ? ) ", 
						status!="0"?"and v.status=? ":"",
						" order by  v.report_time desc "].join("");
		q=q==null?"%%":"%"+q+"%";
		var params=[q,q,q,status];
		console.log(q+"===========")
		dbLib.dbPageQuery(sql,pageNo,pageSize,params,function(err,result){
			res.send(result);
			return;
		});
	};
	
	//关闭举报
	exports.closeVerify = function(req, res){
		var id=req.body.id;
		var usrId=req.session.user.id;
		var sql="update t_report_verify r set r.close_time=NOW(),r.close_user=?,r.`status`=3 where r.id=?";
		var params=[usrId,id];
		dbLib.dbUpdate(sql,params,function(err,result){
			if(err){
				res.send("false");
				return;
			}
			res.send("true");
			return;
		});
	};
	
	//解决举报
	exports.fixVerify = function(req, res){
		var id=req.body.id;
		var usrId=req.session.user.id;
		var sql="update t_report_verify r set r.fix_time=NOW(),r.fix_user=?,r.`status`=2 where r.id=?";
		var params=[usrId,id];
		dbLib.dbUpdate(sql,params,function(err,result){
			if(err){
				res.send("false");
				return;
			}
			res.send("true");
			return;
		});
	};
	
	
	//激活举报
	exports.activeVerify = function(req, res){
		var id=req.body.id;
		var sql="update t_report_verify r set r.`status`=1 where r.id=?";
		var params=[id];
		dbLib.dbUpdate(sql,params,function(err,result){
			if(err){
				res.send("false");
				return;
			}
			res.send("true");
			return;
		});
	};
})( (function(){
    if(typeof exports === 'undefined') {
        window.exports = {};
        return window.exports;
    } else {
        return exports;
    }
})());